home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2403 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: noc.tor.hookup.net!the-fix.sos.on.ca
  2. From: <verneb@the-fix.sos.on.ca>
  3. Date: Sat,20 Jan 96 14:37:24 -0500
  4. Newsgroups: comp.lang.c
  5. Subject: why is this an infinite loop?
  6. Message-ID: <tcpnntpd.16.1.20.14.37.24.2781597121.351172@the-fix.sos.on.ca>
  7. References: <4dp9p5$jm2@news1.wolfe.net>
  8. Organization: the FIX - Kitchener, Ontario CANADA
  9. NNTP-Posting-Host: the-fix.sos.on.ca
  10. X-MajorTCP-Version: MajorTCP/IP [1.81-2]
  11.  
  12. To: INT:neus@wolfenet.com
  13.  
  14. Int:neus@wolfenet.com,
  15.  
  16. I >Beginning c student can't figure out why this small function  to read in a 
  17. I >value for the variable x causes an infinite loop when it receives
  18. I >unexpected 
  19. I >input.
  20. I >
  21. I >double get_x()
  22. I >{
  23. I >int test;
  24. I >double x;
  25. I >
  26. I >printf("Enter a numeric value for x: ");
  27. I >
  28. I >while(scanf("%lf", &x) != 1)/*could be here! change to ==1 */
  29. I >{          
  30. I >printf("ERROR - program expecting a number");
  31. I >printf("Enter a numeric value for x: ");
  32. I >}
  33. I >
  34. I >return x;
  35. I >}
  36. I >
  37. I >                                                                       
  38.  
  39. Verne H. Bohlender
  40. Box 416, Chesley, Ontario.Ca. N0G 1L0
  41. verneb@The-Fix.sos.on.ca
  42. ___
  43. * UniQWK #2158*
  44.  
  45.